// SHp_BPA.cpp: implementation of the CSHp_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/SHp_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSHp_BPA::CSHp_BPA()
{
	m_chType = 'S';
	m_chSubType = 'H';
	m_chChangeCode = '+';

	m_dKpm = 0;
	m_dTpm = 0;
	m_dKpe = 0;
	m_dTpe = 0;
	m_dKw = 0;
	m_dTw = 0;
	m_dTd1 = 0;
	m_dTd2 = 0;
	m_chKd1 = '0';
	m_dT4 = 0;
	m_dK4 = 0;
	m_dKmva = 0;

	m_strCardType[0] = 'S';
}

CSHp_BPA::CSHp_BPA(CSHp_BPA &shpBPA):CUnit_BPA(shpBPA)
{
	m_dKpm = shpBPA.m_dKpm;
	m_dTpm = shpBPA.m_dTpm;
	m_dKpe = shpBPA.m_dKpe;
	m_dTpe = shpBPA.m_dTpe;
	m_dKw = shpBPA.m_dKw;
	m_dTw = shpBPA.m_dTw;
	m_dTd1 = shpBPA.m_dTd1;
	m_dTd2 = shpBPA.m_dTd2;
	m_chKd1 = shpBPA.m_chKd1;
	m_dT4 = shpBPA.m_dT4;
	m_dK4 = shpBPA.m_dK4;
	m_dKmva = shpBPA.m_dKmva;
}

CSHp_BPA::~CSHp_BPA()
{

}

bool CSHp_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSHp_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dKpm = StrToDouble(&buffer[16],5,3);
	if(EndOfSec(&buffer[16],5))
		return true;

	m_dTpm = StrToDouble(&buffer[21],5,3);
	if(EndOfSec(&buffer[21],5))
		return true;

	m_dKpe = StrToDouble(&buffer[26],5,3);
	if(EndOfSec(&buffer[26],5))
		return true;

	m_dTpe = StrToDouble(&buffer[31],5,3);
	if(EndOfSec(&buffer[31],5))
		return true;

	m_dKw = StrToDouble(&buffer[36],5,3);
	if(EndOfSec(&buffer[36],5))
		return true;

	m_dTw = StrToDouble(&buffer[41],5,3);
	if(EndOfSec(&buffer[41],5))
		return true;

	m_dTd1 = StrToDouble(&buffer[46],5,3);
	if(EndOfSec(&buffer[46],5))
		return true;

	m_dTd2 = StrToDouble(&buffer[51],5,3);
	if(EndOfSec(&buffer[51],5))
		return true;

	m_chKd1 = buffer[56];
	if(EndOfSec(&buffer[56],1))
		return true;

	m_dT4 = StrToDouble(&buffer[61],5,4);
	if(EndOfSec(&buffer[61],5))
		return true;

	m_dK4 = StrToDouble(&buffer[66],5,3);
	if(EndOfSec(&buffer[66],5))
		return true;

	m_dKmva = StrToDouble(&buffer[76],4,0);
	if(EndOfSec(&buffer[76],4))
		return true;

	return true;
}

bool CSHp_BPA::UpdateEx(char *buffer)
{
	int i;
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CSHp_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dKpm,&buffer[16],5,3);
	DoubleToStr(m_dTpm,&buffer[21],5,3);
	DoubleToStr(m_dKpe,&buffer[26],5,3);
	DoubleToStr(m_dTpe,&buffer[31],5,3);
	DoubleToStr(m_dKw,&buffer[36],5,3);
	DoubleToStr(m_dTw,&buffer[41],5,3);
	DoubleToStr(m_dTd1,&buffer[46],5,3);
	DoubleToStr(m_dTd2,&buffer[51],5,3);
	buffer[56] = m_chKd1;
	for (i=57;i<61;++i)
	{
		buffer[i] = ' ';
	}
	DoubleToStr(m_dT4,&buffer[61],5,4);
	DoubleToStr(m_dK4,&buffer[66],5,3);
	for (i=71;i<76;++i)
	{
		buffer[i] = ' ';
	}
	DoubleToStr(m_dKmva,&buffer[76],4,0);

	return true;
}